<template>
  <div class="ms-list">
    <el-row class="operation">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">
          <icon style="color: #0088cc" name="home"></icon>
        </el-breadcrumb-item>
        <el-breadcrumb-item>系统设置</el-breadcrumb-item>
        <el-breadcrumb-item>其它设置</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>

    <div style="width: 550px">
      <el-form class="form" label-width="180px" size="small" :model="row.form" ref="formModify">
        <el-form-item label="客户问卷编辑者的权限" prop="settingValue" :rules="[{required: true, message: '必填'}]">
          <el-select v-model="row.form.settingValue" clearable placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit()">提交</el-button>
          <el-button @click="resetForm('formModify')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

  </div>
</template>

<script>
  import Api from '@/api/customer/system/uestionnaire-authority'
  import FormTokenApi from '@/api/system/form-token'

  const formList = {
    LIST: [{
      settingTitleId: '1',
      settingValue: ''
    }],
    token: ''
  }

  export default {
    data () {
      return {
        row: {
          form: {
            settingTitleId: 1,
            settingValue: ''
          }
        },
        options: [{
          value: '2',
          label: '部门主管'
        }, {
          value: '3',
          label: '部门经理'
        }, {
          value: '4',
          label: '老板'
        }],
        value: ''
      }
    },
    created () {
      FormTokenApi.create(response => {
        let status = response.status || 0
        let body = response.data || []
        if (status >= 200 && status <= 204) {
          this.formList.token = body.token || ''
        }
      })
    },
    methods: {
      requestList () {
        Api.getInfo(response => {
          let status = response.status || 0
          let body = response.data || []
          if (status >= 200 && status <= 204) {
          }
        })
      },
      submit () {
        let list = formList.LIST
        if (this.row.form.settingValue !== '') {
          list[0].settingValue = this.row.form.settingValue
          list[0].settingTitleId = this.row.form.settingTitleId
          Api.modify(list, response => {
            let status = response.status || 0
            let body = response.data || []
            if (status >= 200 && status <= 204) {
              this.$message.success('设置成功')
              FormTokenApi.create(response => {
                let status = response.status || 0
                let body = response.data || []
                if (status >= 200 && status <= 204) {
                  this.formList.token = body.token || ''
                }
              })
            } else {
              this.$message.error(body.error || '设置失败')
            }
          })
        }
      },
      resetForm (formName) {
        this.$refs[formName].resetFields()
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
